#!/bin/sh

echo "#######Step 1: Install nfs and rpcbind#######"
sudo yum install -y nfs-utils
sudo yum install -y rpcbind
sudo systemctl enable rpcbind
sudo systemctl enable nfs
sudo systemctl start rpcbind
sudo systemctl start nfs

echo "#######Step 2: Modify firewall#######"
sudo firewall-cmd --permanent --add-service=nfs
sudo firewall-cmd --reload

echo "#######Step 3: Create test directories and files#######"
sudo mkdir -p /data/public
sudo mkdir -p /data/protected
sudo bash -c 'echo "Protected" > /data/protected/protected.txt'


echo "#######Step 4: Modify File Policy#######"
if [ `grep '/data/public' /etc/exports | wc -l` == 0 ];then
  sudo bash -c  "cat >> /etc/exports" <<EOF
/data/public 10.0.2.1/24(rw,sync,no_root_squash,no_all_squash)
/data/protected 10.0.2.1/24(ro,sync,no_root_squash,no_all_squash)
EOF
sudo systemctl reload nfs 
fi


